package com.web.servlet;

import com.bean.Goods;
import com.service.GoodsService;
import com.service.impl.GoodsServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/seByOther")
public class SeByOtherServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map<String,Object> other = new HashMap<String,Object>();
        request.setCharacterEncoding("utf-8");
        String gname = request.getParameter("gname");
        if(!gname.isEmpty())
            other.put("gname",gname);
        String gprice = request.getParameter("gprice");
        if(!gprice.isEmpty())
            other.put("gprice",gprice);
        String classify = request.getParameter("classify");
        if(!classify.isEmpty())
            other.put("classify",classify);
//        request.getRequestDispatcher("")
        GoodsService goodsService = new GoodsServiceImpl();
        //获得商品列表
        List<Goods> goods =goodsService.seByOther(other);
        //将商品列表保存到session中
        request.getSession().setAttribute("goods",goods);
        response.sendRedirect("dataList.jsp");

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
